//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
    gridBody: () => import("./distributor/secondDistributor.vue"),
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  buttons: { view: [], box: [], detail: [] },//扩展的按钮
  methods: {//事件扩展
    getOption (field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        })
      })
      return option;
    },
    onInit () {
      //新建窗口的宽和高
      this.boxOptions.width = 800;
      this.boxOptions.height = 400;

      //   添加操作列
      this.columns.push({
        title: '操作',
        fixed: 'right',
        width: 200,
        render: (h, { row, column, index }) => {
          return h(
            "div", { style: {} }, [
            h(
              "a", {
              props: {},
              style: { "margin-left": "10px" },
              on: {
                click: (e) => {
                  this.$refs.gridBody.open(row,1)
                }
              }
            },
              "产品列表"
            ),
            h(
              "a", {
              props: {},
              style: { "margin-left": "10px" },
              on: {
                click: (e) => {
                  this.$refs.gridBody.open(row,2)
                }
              }
            },
              "授信"
            ),
            h(
              "a", {
              props: {},
              style: { "margin-left": "10px" },
              on: {
                click: (e) => {
                  this.$refs.gridBody.open(row,3)
                }
              }
            },
              "用户"
            ),
          ])
        }
      })

    },
    rowClick ({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    // 点击编辑/新建按钮弹出框后
    async modelOpenAfter (row) {
      if (this.currentAction == "update") {
        this.editFormFields.timeContainer = [row.secondDistributorStartTime, row.secondDistributorEndTime]
      } else {

      }

      return true
    },
    addBefore (formData) { //新建保存前formData为对象，包括明细表
      return this.veriFromTable(formData)
    },
    updateBefore (formData) { //编辑保存前formData为对象，包括明细表、删除行的Id
      return this.veriFromTable(formData)
    },
    // 保存前编辑
    veriFromTable (formData) {
      // console.log("保存前编辑", formData);
      let timeContainer = formData.mainData.timeContainer.split(",")
      let user = sessionStorage.getItem('user')
      formData.mainData.distributorCode = JSON.parse(user).code
      if (timeContainer.length > 0 && timeContainer[0] != "") {
        formData.mainData.secondDistributorStartTime = timeContainer[0]
        formData.mainData.secondDistributorEndTime = timeContainer[1]
      } else {
        this.$Message.error("请选择有效起止日期！")
      }
      return true
    }
  }
};
export default extension;
